package com.hw.common.utils;

import com.hw.common.enums.GenderStatusEnum;
import com.hw.model.vo.overview.DataDetailVO;

import java.util.*;
import java.util.stream.Collectors;

//导出
public class ExportUtil {

    //生成头部
    public static List<List<String>> generateHead(List<String> exportList,LinkedHashMap<String,String> headMap) {
        List<List<String>> list = new ArrayList<List<String>>();
        headMap.entrySet().stream().forEach(entry->{
            if( exportList.contains(entry.getKey()) ){
                List<String> head = new ArrayList<String>();
                head.add(entry.getValue());
                list.add(head);
            }
        });
//        exportList.parallelStream()
//                .filter(v->!StrUtil.isEmpty(headMap.get(v)))
//                .forEach(str->{
//            String strVal = headMap.get(str);
//
//            List<String> head = new ArrayList<String>();
//            head.add(strVal);
//            list.add(head);
//        });
        return list;
    }

    /**
     * 数据概览：明细导出body
     * @return
     */
    public static List<List<String>> generateDetailedBodys(List<String> exportList,List<DataDetailVO> dataDetailVOList){
        return dataDetailVOList.stream().map(dataDetailVO -> {
            ArrayList<String> list = new ArrayList<>();
            if( exportList.contains("id") ){
                list.add(String.valueOf(dataDetailVO.getId()));
            }
            if( exportList.contains("infantName") ) {
                list.add(dataDetailVO.getInfantName());
            }
            if( exportList.contains("clientId") ) {
                list.add(String.valueOf(dataDetailVO.getClientId()));
            }
            if( exportList.contains("fid") ) {
                list.add(String.valueOf(dataDetailVO.getFid()));
            }
            if( exportList.contains("familyName") ) {
                list.add(dataDetailVO.getFamilyName());
            }
            if( exportList.contains("gender") ) {
                GenderStatusEnum byCode = GenderStatusEnum.getByCode(dataDetailVO.getGender());
                if( null != byCode ){
                    list.add(byCode.getName());
                }else{
                    list.add("未知");
                }
            }
            if( exportList.contains("walkday") ) {
                if (null != dataDetailVO.getWalkday()) {
                    list.add(dataDetailVO.getWalkday());
                } else {
                    list.add("");
                }
            }
            if( exportList.contains("birthday") ) {
                list.add(dataDetailVO.getBirthday());
            }
            if( exportList.contains("shotDate") ) {
                list.add(dataDetailVO.getShotDate());
            }
            if( exportList.contains("shotTime") ) {
                list.add(dataDetailVO.getShotTime());
            }
            if( exportList.contains("height") ) {
                list.add(dataDetailVO.getHeight());
            }
            if( exportList.contains("nappyBrand") ) {
                list.add(dataDetailVO.getNappyBrand());
            }
            if( exportList.contains("status") ) {
                //list.add(String.valueOf(dataDetailVO.getStatus()));
                list.add("C");
            }
            return list;
        }).collect(Collectors.toList());
    }

    /**
     * 数据概览：明细导出头部map
     * @return
     */
    public static LinkedHashMap<String,String> getDetailedHeadMap(){
        LinkedHashMap<String, String> detailedHeadMap = new LinkedHashMap<>();
        detailedHeadMap.put("id","Child ID");
        detailedHeadMap.put("infantName","Child name");
        detailedHeadMap.put("clientId","User ID");
        detailedHeadMap.put("fid","Family ID");
        detailedHeadMap.put("familyName","Family name");
        detailedHeadMap.put("gender","Gender");
        detailedHeadMap.put("walkday","Walkday");
        detailedHeadMap.put("birthday","birthday");
        detailedHeadMap.put("shotDate","Shooting date");
        detailedHeadMap.put("shotTime","Shooting time");
        detailedHeadMap.put("height","height");
        detailedHeadMap.put("nappyBrand","Nappy brand");
        detailedHeadMap.put("status","status");
        return detailedHeadMap;
    }
}
